﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class User_ChangeInfo : System.Web.UI.Page
{
    MemberBUS memBUS = new MemberBUS();
    DataTable tbMem = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["ID"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                tbMem = memBUS.checkID(Session["ID"].ToString());
                if (tbMem.Rows.Count > 0)
                {
                    if (tbMem.Rows[0]["M_Gender"].Equals("Male"))
                    {
                        ddlGender.SelectedIndex = 0;
                    }
                    else
                    {
                        ddlGender.SelectedIndex = 1;
                    }
                }
                txtAddress.Text = tbMem.Rows[0]["M_Address"].ToString();
                txtBirhtday.Text = DateTime.Parse(tbMem.Rows[0]["M_Bob"].ToString()).ToShortDateString();
                txtEmail.Text = tbMem.Rows[0]["M_Mail"].ToString();
                txtFullname.Text = tbMem.Rows[0]["M_FullName"].ToString();
                txtID.Text = tbMem.Rows[0]["M_ID"].ToString();
                txtPhone.Text = tbMem.Rows[0]["M_Phone"].ToString();
            }

        }

    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (txtAddress.Text.Equals("") || txtBirhtday.Text.Equals("") || txtEmail.Text.Equals("") || txtFullname.Text.Equals("") || txtPhone.Text.Equals(""))
        {
            lblError.Text = "You must enter enough information";
        }
        else
        {
            bool check = memBUS.updateMember(txtID.Text, txtFullname.Text, DateTime.Parse(txtBirhtday.Text), ddlGender.SelectedValue, txtPhone.Text, txtAddress.Text, txtEmail.Text);
            if (check)
            {
                lblError.Text = "Update Success !";
            }
            else
            {
                lblError.Text = "Update Error";
            }
        }
    }
}